package com.mostromas.ess.system.feign;

import com.mostromas.ess.entities.SysMenu;
import com.mostromas.ess.entities.SysUser;
import com.mostromas.ess.feign.IFeignSystemController;
import com.mostromas.ess.system.service.ISysMenuService;
import com.mostromas.ess.system.service.ISysUserService;
import com.mostromas.ess.util.base.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class FeignSystemController implements IFeignSystemController {

    @Autowired
    private ISysUserService sysUserService;

    @Autowired
    private ISysMenuService sysMenuService;

    /**
     * 通过用户名查询用户信息
     * @param username 用户名
     * @return
     */
    @Override
//    @PreAuthorize(("hasAuthority('user:search')"))
    public SysUser findUserByUsername(String username) {
        return sysUserService.findByUsername(username);
    }

    /**
     * 通过用户id查询拥有权限
     * @param userId 用户id
     * @return
     */
    @Override
//    @PreAuthorize(("hasAuthority('user:search')"))
    public List<SysMenu> findMenuByUserId(String userId) {

        List<SysMenu> sysMenus = sysMenuService.findByUserId(userId);
        return sysMenus;
    }

    /**
     * 校验用户名是否存在
     * @param username
     * @return
     */
    @Override
    public Result checkUsername(String username) {
        Result result = sysUserService.checkUsername(username);
        return result;
    }
}
